package com.mygdx.game.Scenes;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.mygdx.game.MyGdxGame;

public class ActiveCharacter_Pope extends Actor {
    public static boolean Collision = false;
    public static float x;
    public static float y;
    public static float width;
    public static float heigth;



    public static float statetime = 0;
    TextureRegion[] walkFrame;
    TextureRegion currentFrame;
    Animation aniRight;

    public ActiveCharacter_Pope(float x, float y){
        this.x = x;
        this.y = y;
        this.show();
    }
    public void show() {
        Texture[] temp = new Texture[4];
        walkFrame =new TextureRegion[4];
        for(int i=0;i<4;i++){
            temp[i] = new Texture(Gdx.files.internal("Character/Sorcerer ("+(4-i)+").png"));
           width =  temp[i].getWidth();
           heigth = temp[i].getHeight();
            walkFrame[i] = new TextureRegion(temp[i],0,0,512,512);
        }
        aniRight = new Animation(0.1f,walkFrame);
    }

    public void update(){

        if(Gdx.input.isKeyPressed(Input.Keys.NUMPAD_6)){
            x+=20f;
            System.out.println("RIGHT");
        }
        if(Gdx.input.isKeyPressed(Input.Keys.NUMPAD_4)){
            x-=20f;
            System.out.println("LEFT");
        }
        if(Gdx.input.isKeyPressed(Input.Keys.NUMPAD_8)){
            y+=20f;
            System.out.println("UP");
        }
        if(Gdx.input.isKeyPressed(Input.Keys.NUMPAD_5)){
            y-=20f;
            System.out.println("DOWN");
        }
        //左边界-100 右边界1550 上边界700 下边界-100
        if (x<-100){
            x=-100;
        }
        if (x> MyGdxGame.V_WIDTH)
        {
            x=MyGdxGame.V_WIDTH;
        }
        if (y<-100)
        {
            y=-100;
        }
        if(y>MyGdxGame.V_HEIGHT){
            y=MyGdxGame.V_HEIGHT;
        }

    }

    public void aniCheck(){
            currentFrame = (TextureRegion) aniRight.getKeyFrame(statetime,true);
    }
    public void Coll(){

        currentFrame = (TextureRegion) aniRight.getKeyFrame(statetime,true);

    }

    @Override
    public void draw(Batch batch, float parentAlpha) {
        if (Collision==false) {
            statetime += Gdx.graphics.getDeltaTime();
            this.update();
            this.aniCheck();
            batch.draw(currentFrame,x,y);
        }
        else {
            statetime += Gdx.graphics.getDeltaTime();
            this.update();

            this.Coll();
            batch.draw(walkFrame[0],x,y);

        }


    }
    @Override
    public void act(float delta) {
        super.act(delta);
    }
}
